<extend name="./Application/Admin/View/Layout/application.html"/>
<block name="css">
    <link rel="stylesheet" href="__PUBLIC__/assets/admin/css/common.css">
</block>
<block name="content">
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong> /
                    <small>User Manage</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{:U('AuthSet/add_user')}}" class="am-btn am-btn-default"><span
                                    class="am-icon-plus"></span> 新增
                            </a>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-form-group">
                        <select data-am-selected="{btnSize: 'sm'}">
                            <option value="option1">所有类别</option>
                            <option value="option2">IT业界</option>
                            <option value="option3">数码产品</option>
                            <option value="option3">笔记本电脑</option>
                            <option value="option3">平板电脑</option>
                            <option value="option3">只能手机</option>
                            <option value="option3">超极本</option>
                        </select>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-input-group am-input-group-sm">
                        <input type="text" class="am-form-field">
                        <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="button">搜索</button>
          </span>
                    </div>
                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check"><input type="checkbox"/></th>
                                <th class="table-id">ID</th>
                                <th class="table-title">用户名</th>
                                <th class="table-type">所属用户组</th>
                                <th class="table-author am-hide-sm-only">邮箱</th>
                                <th class="table-date am-hide-sm-only">创建时间</th>
                                <th class="table-date am-hide-sm-only">账号状态</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="users" id="user">
                                <tr data-id="{{$user.id}}">
                                    <td><input type="checkbox"/></td>
                                    <td>{{$user.id}}</td>
                                    <td><a href="#">{{$user.username}}</a></td>
                                    <td>{{$user.groups|pluck=###,'title'|implode=', '}}</td>
                                    <td class="am-hide-sm-only">{{$user.email}}</td>
                                    <td class="am-hide-sm-only">{{$user.created_at|date="Y-m-d H:i:s", ###}}</td>
                                    <td class="am-hide-sm-only attrs" data-status="{{$user.status}}">
                                        <eq name="user.status" value="1">
                                            <a href="javascript:;"
                                               class="am-btn am-btn-success am-btn-xs status">已启用</a>
                                            <else/>
                                            <a href="javascript:;" class="am-btn am-btn-danger am-btn-xs status">已禁用</a>
                                        </eq>
                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="{{:U('edit_user', array('id'=>$user[id]))}}"
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                        class="am-icon-pencil-square-o"></span> 编辑
                                                </a>
                                                <neq name="user.id" value="1">
                                                    <a class="delete am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">

                                                        <span class="am-icon-trash-o"></span> 删除
                                                    </a>
                                                </neq>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </volist>

                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {{$count}}条记录

                        </div>
                        <hr/>
                        <p>注：.....</p>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>
    <!-- content end -->
</block>
<block name="js">
    <script src="__PUBLIC__/vendor/assets/js/jquery.min.js"></script>
    <script>
        $(function () {
            //删除
            $('.delete').click(function () {
                var id = $(this).parents('tr').data('id')
                var _this = $(this)
//                console.log(id);
                $.ajax({
                    type: 'post',
                    url: "{{:U('delete')}}",
                    data: {id: id},
                    success: function () {
                        _this.parents('tr').fadeOut(400);
                    }
                });
                return false;
            })
            //改变状态
            $('.attrs').click(function () {
                var info = {
                    id: $(this).parents('tr').data('id'),
                    attr: $(this).attr('data-status')
                };
                var _this = $(this);
                $.ajax({
                    type: 'post',
                    url: "{{:U('change_attr')}}",
                    data: info,
                    success:function () {
                        window.location.reload();
                    }
                })
                return false;
            })
        })
    </script>
</block>
